<?php

Class User extends CI_Model {

    function login($username, $password) {
        $this->db->select('id, username, password');
        $this->db->from('admin');
        $this->db->where('username', $username);
        $this->db->where('password', MD5($password));
        $this->db->limit(1);

        $query = $this->db->get();

        if ($query->num_rows() == 1) {
            return $query->result();
        } else {
            return false;
        }
    }

    function get_user_all() {
        $query = $this->db->query("SELECT * FROM admin");
        $data = array();
        if ($query->num_rows == 1) {
            foreach ($query->result() as $row) {
                $data[] = $row;
            }
        }
        return $query->row();
    }

    function edit_admin() {
        $q = "SELECT * FROM admin WHERE id = 1";
        $query = $this->db->query($q);
        return $query->row();
    }

    function simpan_edit_admin($username, $password) {
        $data = array(
            'id' => 1,
            'username' => 'admin',
            'password' => MD5($password)
        );
        $this->db->where('id', 1);
        $this->db->update('admin', $data);
    }

}
?>